﻿#include "SmartViewView.h"

SmartViewView::SmartViewView(QWidget *parent)
    : ElaWidget(parent)
    , mOptionLayout(new QHBoxLayout)
    , mStackedLayout(new QStackedLayout)
{
    this->setWindowButtonFlags(ElaAppBarType::CloseButtonHint);
    this->setFont(QFont("Segoe UI", 20));

    QVBoxLayout *layout = new QVBoxLayout(this);
    layout->addLayout(mOptionLayout, 1);
    layout->addLayout(mStackedLayout, 9);
}

void SmartViewView::addOptionView(QWidget *view)
{
    mStackedLayout->addWidget(view);
    ElaIconButton *button = new ElaIconButton(ElaIconType::Eye, this);
    mOptionLayout->addWidget(button);
    mButtonMap.insert(button, mStackedLayout->count() - 1);
    connect(button, &QAbstractButton::clicked, this, &SmartViewView::onOptionButtonClicked);
}

void SmartViewView::setOptionIcon(int index, ElaIconType::IconName type)
{
    ElaIconButton *button = mButtonMap.key(index);
    button->setAwesome(type);
}

void SmartViewView::onOptionButtonClicked()
{
    ElaIconButton *button = qobject_cast<ElaIconButton *>(sender());
    if (button && mButtonMap.contains(button)) {
        int index = mButtonMap.value(button);
        mStackedLayout->setCurrentIndex(index);
    }
}
